<?php
namespace App\Api\Eloquent;

class Code extends Model
{
    /**
     * 设置逐渐 id
     *
     * @var string
     */
    protected $primaryKey = 'code';

    /**
     * 设置主键 id 不自增
     *
     * @var bool
     */
    public $incrementing = false;

    /**
     * 实例化模型时, 可批量赋值属性白名单
     *
     * @var array
     */
    protected $fillable = [
        'code', 'type_id', 'name', 'parent_code', 'description', 'sort', 'tree'
    ];

    public static function getcode($cate){
        $codes=Code::where('type_id','like','%'.$cate.'%')
            ->get();
        foreach($codes as $code){
            $code_list[$code->type_id][$code->code]=$code;
        }
        return $code_list;
    }
}